Function.RegisterNamespace("Test.System.Script");

[Fixture,Trait("Integration")]
Test.System.Script.ScriptLoadStrategy=function(){
    [Fixture]
    function Import(){
        [Fact]
        function ImportsScript(){
            var target="Object.Global().actual=Object.Global().expected";
            var targetFile=System.IO.Path.Combine(System.Environment.GetWorkingDirectory(),"ScriptLoadStrategyIntegrationTests.Import.ImportsScript.tmp");
            System.IO.File.SaveFile(targetFile,target);
            var expected=Object.Global().expected="expected";
            var actual=null;
            
            System.Script.ScriptLoader.Import(targetFile);
            actual=Object.Global().actual;
            System.IO.File.DeleteFile(targetFile);
            delete Object.Global().expected;
            delete Object.Global().actual;
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function CallsCallbackAfterImport(){
            var target="Object.Global()";
            var targetFile=System.IO.Path.Combine(System.Environment.GetWorkingDirectory(),"ScriptLoadStrategyIntegrationTests.Import.ImportsScript.tmp");
            System.IO.File.SaveFile(targetFile,target);
            var callback=function(){
                actual=true;
            }
            var actual=false;
            
            System.Script.ScriptLoader.Import(targetFile,callback);
            System.IO.File.DeleteFile(targetFile);
            
            Assert.True(actual);
        }

        [Fact]
        function PassesPathToCallbackAfterImport(){
            var target="Object.Global()";
            var expected=System.IO.Path.Combine(System.Environment.GetWorkingDirectory(),"ScriptLoadStrategyIntegrationTests.Import.ImportsScript.tmp");
            System.IO.File.SaveFile(expected,target);
            var callback=function(path){
                actual=path;
            }
            var actual=null;
            
            System.Script.ScriptLoader.Import(expected,callback);
            System.IO.File.DeleteFile(expected);
            
            Assert.Equal(expected,actual);
        }
    }
    
    [Fixture]
    function Load(){
        [Fact]
        function LoadsScript(){
            var expected=Object.Global().expected="expected";
            var target="Object.Global().actual=Object.Global().expected";
            var actual=null;
            
            System.Script.ScriptLoader.Load(target);
            actual=Object.Global().actual;
            delete Object.Global().expected;
            delete Object.Global().actual;
            
            Assert.Equal(expected,actual);
        }
    }
}
